function isExplorerAnIssue(){
	var msg = '';
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
		var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ffversion>=3)
			return false;//"You're using FF 3.x or above";
		else if (ffversion>=2)
			return true; //"You're using FF 2.x";
		else if (ffversion>=1)
			return true; //"You're using FF 1.x";
	}
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	 if (ieversion>=9)
	 	return true; //"You're using IE9 or above";
	 if (ieversion>=8)
		return true; //"You're using IE8 or above";
	 else if (ieversion>=7)
	  	return true; //"You're using IE7.x";
	 else if (ieversion>=6)
	  	return true; //"You're using IE6.x";
	 else if (ieversion>=5)
	  	return true; //"You're using IE5.x";
	}
	if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
	 var oprversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	 if (oprversion>=10)
	  return true; //"You're using Opera 10.x or above";
	 else if (oprversion>=9)
	  return true; //"You're using Opera 9.x";
	 else if (oprversion>=8)
	  return true; //"You're using Opera 8.x";
	 else if (oprversion>=7)
	  return true; //"You're using Opera 7.x";
	}
	return false;
}

function jQueryFormValidator(form,customRules) {
	$(form).validate({	
		showErrors: function(errorMap, errorList) {
			$(form).find("input").each(function() {
				$(this).removeClass("error");
			});
			$(".errorDiv").html("");
			if(errorList.length) {
				$(".errorDiv").html(errorList[0]['message']);
				$(errorList[0]['element']).addClass("error");
			}
		},
                rules: customRules ? customRules : {}
		
	});
	
	$("#unitId").change(function(){
		selectUnit($(this).val());
	});

}

function editText(sVal){
	var _newContent = "";
	for(i=0;i<sVal.length;i++){
		if( sVal.charCodeAt(i)==10){
			_newContent += '\u001B';
		}else{
			var _char = fixReservedURLChar(sVal.charCodeAt(i));
			_newContent += _char == '' ? sVal.charAt(i) : _char;
		}
	}
	return _newContent;
}

function fixReservedURLChar(charCode){
	var newChar = '';
	switch(charCode){
		//%21  %2A	%27	%28	%29	%3B	%3A	%40	%26	%3D	%2B	%24	%2C	%2F	%3F	%23	%5B	%5D %25
		//!		*	 '	 (	 )	 ;	 :	 @	 &	 =	 +	 $	 ,	 /	 ?	 #	 [	 ]	 %
		case 33: newChar = '%21';break;
		case 37: newChar = '%25';break;
		case 42: newChar = '%2A';break;
		case 39: newChar = '%27';break;
		case 40: newChar = '%28';break;
		case 41: newChar = '%29';break;
		case 59: newChar = '%3B';break;
		case 58: newChar = '%3A';break;
		case 64: newChar = '%40';break;
		case 38: newChar = '%26';break;
		case 61: newChar = '%3D';break;
		case 43: newChar = '%2B';break;
		case 36: newChar = '%24';break;
		case 44: newChar = '%2C';break;
		case 47: newChar = '%2F';break;
		case 63: newChar = '%3F';break;
		case 35: newChar = '%23';break;
		case 91: newChar = '%5B';break;
		case 93: newChar = '%5D';break;
	}
	return newChar;
}

function loadMap(){
    $("#settings").colorbox({ width:"640px", height:"440px", iframe:true });
    $("#addSRM").colorbox({ width:"640px", height:"440px", iframe:true });
    $("#pointerReport").colorbox({ width:"640px", height:"440px", iframe:true });
    $("#scoreCardReport").colorbox({ width:"640px", height:"440px", iframe:true });
    $("#projectReport").colorbox({ width:"640px", height:"440px", iframe:true });
    $("#leftBar").accordion({
        active: "#nav-mapas",
        header: ".accordionHeader",
        icons: false
    });
    //$("#container.graphview").scrollTo( "left:50%", 1000 );
    Modernizr.load();

    // Reacomodar tooltips
    $("li.scoresemaphore").each(function(index, element){
        var modal = $(this).children("a").children("div.modal");
        var x = $(this).position().left;
        var y = $(this).position().top;
        $(this).bind("mouseenter mouseleave",function(event){
            if(event.type == "mouseenter")
            {
                modal.css("visibility","hidden").css("display","block").css("opacity","0");
                if(y > $("#container").height()/2)
                    modal.css("top","-"+(modal.height()+20)+"px")
                if(x > $("#container").width()/2)
                    modal.css("left","-"+(modal.width()+20)+"px")
                modal.css("visibility","visible").delay(100).animate({ opacity:1.0 },300);
            }
            else
                modal.delay(100).animate({opacity:0},200).css("visibility","hidden")
        });
    });

    $.datepicker.regional['es'] = {
        closeText: 'Cerrar',
        prevText: '<Ant',
        nextText: 'Sig>',
        currentText: 'Hoy',
        monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
        monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'],
        dayNames: ['Domingo', 'Lunes', 'Martes', 'Mi&eacute;rcoles', 'Jueves', 'Viernes', 'S&aacute;bado'],
        dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sab'],
        dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sa'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
    $.datepicker.setDefaults($.datepicker.regional['es']);
    $("#periodPicker").datepicker($.datepicker.regional['es']);
    $("#periodPicker").datepicker("option", "showAnim", "blind");
    $("#periodPicker").datepicker("setDate", $.datepicker.parseDate('dd/mm/yy', $("#date").text()));
    $("#periodPicker").change(function(){
        window.location.href = "updateSession.do?location=mapFinalUser.do&date=" + $("#periodPicker").val();
    /*
               if($("#scores").data("period") != $("#periodPicker").val())
               {
                   $("#scores").data("period", $("#periodPicker").val());
                   var ids = '"{';
                   $(".scorecard").each(function(index, item){
                       if(index>0) ids += ',';
                       ids += $(this).attr("scoreid");
                   });
                   ids += '}"';

                $.getJSON('drillScoreCard.do', { "update": ids, "date" : '"'+$("#periodPicker").val()+'"' }, function(data) {
                      $.each(data, function(key, val) {
                        $("#scores").data(key,val);
                        if($(".scorecard[scoreid="+key+"]").length == 0)
                            createScoreCard(scoreParentNode, key);
                        else
                            updateScoreCard(key);
                      });
                    });
               }*/
    });

    $("#comprador").change(function(){
        window.location.href = "updateSession.do?location=mapFinalUser.do&comparation=" + $("#comprador").val();

    });
/*
        $("li.scoresemaphore").mouseover(function(){
            $(this).find("div").animate({opacity:0.8},750);
        });

        $("li.scoresemaphore").mouseout(function(){
            $(this).find("div").animate({opacity:0},250);
        });
                 */
}
function loadView(){
    $("#settings").colorbox({ width:"640px", height:"440px", iframe:true });
    $("#addSRM").colorbox({ width:"640px", height:"440px", iframe:true });
    $("#pointerReport").colorbox({ width:"640px", height:"440px", iframe:true });
    $("#scoreCardReport").colorbox({ width:"640px", height:"440px", iframe:true });
    $("#projectReport").colorbox({ width:"640px", height:"440px", iframe:true });
    $(".annotate").colorbox({
        width:"692px",
        height:"400px",
        iframe:true
    });
    $(".dashboard").colorbox({
        width:"990px",
        height:"720px",
        iframe:true
    });
    $(".send").colorbox({
        width:"990px",
        height:"720px",
        iframe:true
    });

    $("#leftBar").accordion({
        active: "#nav-vistas",
        header: ".accordionHeader",
        icons: false
    });
    //$("#container.graphview").scrollTo( "left:50%", 1000 );
    $("#scores").data("lastExpanded",-1);

    $("#scores").data( document.getElementById("parentScorecard").value,
    {
        "name": $("#parentScoreCardName").text(),
        "score": $("#parentScore").text(),
        "color": $("#parentScoreColor").text(),
        "children": $("#childrenCount").val(),
        "type": $("#parentScoreCardClass").text(),
        "visible":true,
        "graphposition":{
            "x":($("#container").width()-$("#scores .parent").width())/2+"px",
            "y":"10px"
        },
        "listposition":{
            "x":"0px",
            "y":"0px"
        }
    });

    $("#scores li.parent").css("left",$("#scores").data(document.getElementById("parentScorecard").value).graphposition.x).css("top",$("#scores").data(document.getElementById("parentScorecard").value).graphposition.y);
    $("#scores li.parent").attr("graphx",$("#scores").data(document.getElementById("parentScorecard").value).graphposition.x).attr("graphy",$("#scores").data(document.getElementById("parentScorecard").value).graphposition.y);
    if($("#childrenCount").val() > 0) linkexpansion($("#scores").find("a.expand"));

    $.datepicker.regional['es'] = {
        closeText: 'Cerrar',
        prevText: '<Ant',
        nextText: 'Sig>',
        currentText: 'Hoy',
        monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
        monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'],
        dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
        dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sáb'],
        dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sá'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
    $.datepicker.setDefaults($.datepicker.regional['es']);
    $("#periodPicker").datepicker($.datepicker.regional['es']);
    $("#periodPicker").datepicker("option", "showAnim", "blind");
    $("#periodPicker").datepicker("setDate", $.datepicker.parseDate('dd/mm/yy', $("#date").text()));
    $("#periodPicker").change(function(){
        window.location.href = "updateSession.do?location=mainFinalUser.do&date=" + $("#periodPicker").val();
    });

    $("#comprador").change(function(){
        window.location.href = "updateSession.do?location=mainFinalUser.do&comparation=" + $("#comprador").val();

    });

    $("#scores a.expand, #scores a.collapse, #scores a.back").live("click",function(){
        linkexpansion(this);
    });

    $("#scores li").live("mouseover",function(){
        if($("#container").hasClass("graphview"))
            $("#scores li.parent").draggable({
                delay: 250
            });
        else
            $("#scores li.parent").draggable({
                delay: 10000000000
            });
    })

    //setInterval( "checkAnchor()", 250);

    $("#viewSelector").click(toggleView);
    setInterval("actualizarPosiciones()",500);
}
function toggleView(){
    $("#scorecontainer").animate({
        opacity:0
    },200,"swing",function(){
        $("#viewSelector").toggleClass("graphViewIcon").toggleClass("listViewIcon");
        $("#container").toggleClass("graphview").toggleClass("listview");
        $("#scores .parent").find("a.collapse").addClass("expand").removeClass("collapse");
        if($("#container").hasClass("listview")) {
            $("#container").css("width","725px").find("#scores").css("width","725px").css("left","0px");
            $(".listview .parent").css("width","725px").css("left","0px").children("ul").remove();
        /*
            $("#scores, #scores li").css("width", "725px");

            $("#scores li").each(function(index, element) {
                $("#scores").data($(this).attr("scoreid")).graphposition.x = $(this).css("left");
                $("#scores").data($(this).attr("scoreid")).graphposition.y = $(this).css("top");
                $(this).css("left",$("#scores").data($(this).attr("scoreid")).listposition.x).css("top",$("#scores").data($(this).attr("scoreid")).listposition.y);
            });

            $("#scores").css("left",-725*($("li[parentid="+$("#scores").data("lastExpanded")+"]").parents("ul").length-1)+"px");
            $("#scores").find("ul").css("left","725px");
*/
        } else {
            /*
            $(".graphview #scores li").each(function(index, element) {
                $("#scores").data($(this).attr("scoreid")).listposition.x = $(this).css("left");
                $("#scores").data($(this).attr("scoreid")).listposition.y = $(this).css("top");
                $(this).css("left",$("#scores").data($(this).attr("scoreid")).graphposition.x).css("top",$("#scores").data($(this).attr("scoreid")).graphposition.y);
            });
            $("#scores ul").css("left","-25px");*/
            $("#container").css("width","725px").find("#scores").css("width","725px");
            $(".graphview .parent").css("width","140px").css("left",($("#container").width()-$(".graphview .parent").width())/2 +"px").children("ul").remove();
            if($("hasChildren")) graphviewExpand($("#scores").find("a.expand"));
            $("#scorecontainer li").each(function(index, element){
                $(this).css("left",$(this).attr("graphx")+"px");
            });
        }
        //actualizarPosiciones();
        $("#scorecontainer").animate({
            opacity:1
        },250);

    });
}

function leaves(list)
{
    var qty = 0;
    $(list).children("li").each(function(index, element){
        if($(this).children("ul").length == 0)
            qty++;
        else
            qty += leaves($(this).children("ul"));
    });
    return qty;
}

function linkexpansion(node){
    if($("#container").hasClass("listview"))
    {
        if($(node).hasClass("back"))
            listviewCollapse(node);
        else
            listviewExpand(node);
    }
    else
    {
        if($(node).hasClass("expand"))
            graphviewExpand(node);
        else
            graphviewCollapse(node);
    }
}

function actualizarPosiciones()
{
    if($("#container").hasClass("listview")) return;
    $("#scorecontainer ul").each(function(index, element)
        {
            // Calcular hojas para cada árbol
            var qty = leaves($(this));
            // Ancho de lista y línea
            $(this).css("width",qty*190+"px");
            if( $(this).children("li").length > 1 )
                $(this).children("span.horizontal").css("width", ((qty-1)*175+4)+"px");
//            if( qty > 1 && $(this).parent("li").nextAll("li").length > 0 && $(this).parent("li").next("li").position().left <= $(this).parent("li").position().left+87.5*qty )
            if( qty > 1 && $(this).parent("li").nextAll("li").length > 0 && $(this).parent("li").next("li").position().left < $(this).parent("li").position().left+125*qty )
            {
                if($(this).parent("li").prev("li").length > 0)
                    $(this).parent("li").attr("graphx",parseInt($(this).parent("li").attr("graphx"))+87.5*(qty-1));
                $(this).parent("li").nextAll("li").each(function(i,e){
                    console.log("Damidram");
                   $(this).attr("graphx",parseInt($(this).attr("graphx"))+175*(qty-1));
                });
            }
            if( $(this).parent("li").nextAll("li").length == 0 && !$(this).parent("li").hasClass("parent") )
                    $(this).parent("li").attr("graphx",$(this).parent("li").parent("ul").children(".horizontal").width()+11);
        });
        $("#scorecontainer li").each(function(index, element)
        {
            $(this).animate({left:$(this).attr("graphx")+"px"},50);
        });
}

function listviewCollapse(node){
    $("#scores").animate({
        left: "+=725px"
    }, 200, "swing", function()

    {
        $(node).parents("ul").css("display","block");
        $(node).parent().parent().parent().find("ul").remove();
    });
}
function listviewExpand(node){
    $(node).removeClass("expand").addClass("collapse");
    var scoreParentNode = $(node).parent().parent().parent();
    var parent = scoreParentNode.attr("scoreid");

    $.getJSON('drillScoreCard.do', {
        'scoreCard': parent
    }, function(data) {
        $.each(data, function(key, val) {
            $("#scores").data(key,val);
            if($(".scorecard[scoreid="+key+"]").length == 0)
                createScoreCard(scoreParentNode, key);
        });
        scoreParentNode.children("ul").css("display","block");
        $("#scores").animate({
            opacity:0.2,
            left: "-=275px"
        }, 100, "swing", function(){
            $("#scores").animate({
                opacity:1,
                left:"-=450px"
            }, 200)
        });
    });
}

function graphviewCollapse(node){
    var scoreParentNode = $(node).parent().parent().parent();
    $(node).removeClass("collapse").addClass("expand");
    $("#scores").data("lastExpanded", scoreParentNode.attr("parentid"));
    scoreParentNode.find("ul").fadeOut(250, function()
    {
        scoreParentNode.find("a.collapse").removeClass("collapse").addClass("expand");
        scoreParentNode.find("ul").remove();
        //setTimeout("actualizarPosiciones()",1000);
        $("#container").scrollTo(scoreParentNode);
    });
}
/*
    var scoreParentNode = $(node).parent().parent().parent();
    var children = $("#scores").data(scoreParentNode.attr("scoreid")).children;
    $(node).removeClass("collapse").addClass("expand");
    $("#scores").data("lastExpanded", scoreParentNode.attr("parentid"));
    scoreParentNode.find("ul").fadeOut(350, function()
    {
        scoreParentNode.find("a.collapse").removeClass("collapse").addClass("expand");
        scoreParentNode.parents("ul").animate({
            width:"-="+children*100+"px"
            }, 0);
        if(!scoreParentNode.hasClass("parent"))
        {
            if( scoreParentNode.prevAll("li").length > 0 )
            {
                if( scoreParentNode.nextAll("li").length > 0 )
                    scoreParentNode.animate({
                        left:"-="+(children-2)*200+"px"
                        }, 500);
                else
                    scoreParentNode.animate({
                        left:"-="+(children-1)*200+"px"
                        }, 500);
            }
            scoreParentNode.nextAll("li").animate({
                left:"-="+200*(children-1)+"px"
                },500);
            if( scoreParentNode.siblings("li").length > 0 )
                scoreParentNode.parents("ul").children("span.horizontal").animate({
                    width:"-="+200*(children-1)+"px"
                    },500);
            scoreParentNode.parents("li").each(function(index,element)
            {
                if( $(this).prevAll("li").size() > 0 )
                    $(this).animate({
                        left:"-="+(children-1)*200+"px"
                        },100);
                else
                    $(".graphview .parent").animate({
                        left:"-="+children*25/(index+1)+"px"
                        },100);
                $(this).nextAll("li").animate({
                    left:"-="+(children-1)*200+"px"
                    },100);
            });
        }
        else
        {
            scoreParentNode.parent("ul").css("width","725px");
            scoreParentNode.animate({
                left:$("#container").width()/2
            },250);
        }
        scoreParentNode.find("ul").remove();
        $("#container").scrollTo(scoreParentNode);
    });
*/

function graphviewExpand(node){
    $(node).removeClass("expand").addClass("collapse");
    var scoreParentNode = $(node).parent().parent().parent();
    var parent = scoreParentNode.attr("scoreid");
    $("#scores").data("lastExpanded",parent);
    $.getJSON('drillScoreCard.do', {
        'scoreCard': parent
    }, function(data) {
        $.each(data, function(key, val) {
            $("#scores").data(key,val);
            if($(".scorecard[scoreid="+key+"]").length == 0)
                createScoreCard(scoreParentNode, key);
            else
                updateScoreCard(key);


/*
            var children = $("#scores").data(scoreParentNode.attr("scoreid")).children;
            scoreParentNode.parents("ul").animate({
                width:"+="+children*100+"px"
                }, 0);
            if(!scoreParentNode.hasClass("parent"))
            {
                if( scoreParentNode.prevAll("li").size() > 0 )
                {
                    if( scoreParentNode.nextAll("li").size() > 0 )
                        scoreParentNode.animate({
                            left:"+="+(children-1)*100+"px"
                            },500); 
                    else
                        scoreParentNode.animate({
                            left:"+="+(children-1)*100+"px"
                            },500);
                }
                else
                    scoreParentNode.nextAll("li").animate({
                        left:"+="+100*(children-1)+"px"
                        },500);
                if(scoreParentNode.siblings("li").length > 0)
                    scoreParentNode.parents("ul").children("span.horizontal").animate({
                        width:"+="+100*(children-1)+"px"
                        },500);
                scoreParentNode.parents("li").each(function(index,element)
                {
                    if( $(this).prevAll("li").size() > 0 )
                        $(this).animate({
                            left:"+="+(children-1)*100+"px"
                            },100);
                    else
                        $(".graphview .parent").animate({
                            left:"+="+children*25/(index+1)+"px"
                            },100);
                    $(this).nextAll("li").animate({
                        left:"+="+children*50+"px"
                        },100);
                });
            }
            */
            scoreParentNode.children("ul").css("display","block").css("width",190*children+"px").css("left",(-95*children+80)+"px").css("bottom","0px");
            scoreParentNode.children("ul").children("li").each(function(index){
                $(this).attr("graphy","30px");
                $(this).attr("graphx",index*160+15*(index+1)/*+20*/);
                $(this).css("top",$(this).attr("graphy"));
                $(this).css("display","block").css("margin","2px");
                $(this).prepend('<span class="line" parent="'+scoreParentNode.attr("scoreid")+'" style="height:15px; left:76px; top:-15px;"></span>');
            });
            $(".line[parent="+scoreParentNode.attr("scoreid")+"]").css("display","block").animate({
                opacity:1.0
            }, 500);
            //actualizarPosiciones();
            $("#container").scrollTo(scoreParentNode.children("ul").find(".toolbar").first());
        });
    });

    
    //scoreParentNode.find("ul").each(function(index, element)
    

}

function updateScoreCard(id){
    var node = $(".scorecard[scoreid="+id+"]");
    var tmp = $("#scores").data(id);
    node.children(".detail").children(".name").text(tmp.name);
    node.children(".detail").children(".dimension").text(tmp.score);
    if(node.children(".detail").children("p").children("a").length==4 && tmp.children == 0)
        node.children(".detail").children("p").children("a.expand").remove(); // and collapse if necessary... TODO
    else if(node.children(".detail").children("p").children("a").length==3 && tmp.children > 0)
        node.children(".detail").children("p").apprend('<a href="#'+id+'" class="expand">+</a>');
}

function createScoreCard(scoreParentNode, id){
    if(scoreParentNode.children("ul").length==0)
    {
        scoreParentNode.append('<ul id="score-'+scoreParentNode.attr("scoreid")+'"></ul>');
        scoreParentNode.children("ul").append(
            '<div class="listheader">'+
            '<span class="semaphore" style="background-color:'+$("#scores").data(scoreParentNode.attr("scoreid")).color+'"></span>'+
            '<span class="name">'+$("#scores").data(scoreParentNode.attr("scoreid")).name+'</span>'+
            '<span class="type">'+$("#scores").data(scoreParentNode.attr("scoreid")).type+'</span>'+
            '<a href="#" class="back"></a>'+
            '<a href="addNote.do?scoreCard='+scoreParentNode.attr("scoreid")+'" class="annotate"></a>'+
            '<a href="popableWindow.do?url=dashboardNotes.do&params=scoreCard:'+scoreParentNode.attr("scoreid")+'" class="send"></a>'+
                '<a href="popableWindow.do?url='+($("#scores").data(scoreParentNode.attr("scoreid")).type == 'Indicador' ? 'dashboardPointer': ($("#scores").data(scoreParentNode.attr("scoreid")).type == 'Proyecto' ? 'dashboardProject' : 'dashboardScoreCard'))+'.do&params=scoreCard:'+ scoreParentNode.attr("scoreid") +'" class="dashboard"></a>'+
            '</div>');
    }
    scoreParentNode.children("ul").append('<li class="scorecard" parentid="'+scoreParentNode.attr("scoreid")+'" scoreid="'+id+'" children="0">'+
        '<div class="detail">'+
        '<div class="name">'+$("#scores").data(id).name+'</div>'+
        '<span class="semaphore" style="background-color:'+$("#scores").data(id).color+'"></span>'+
        '<div class="data">'+
        '<span class="label">Score</span><span class="score">'+$("#scores").data(id).score+'</span>'+
        '<span class="label">Ponderaci&oacute;n</span><span class="weight">'+$("#scores").data(id).weight+'</span>'+
        '<span class="label">Tipo</span><span class="type">'+$("#scores").data(id).type+'</span>'+
        '</div>'+
        '<p class="toolbar">'+
        '<a href="addNote.do?scoreCard='+id+'" class="annotate"></a>'+
        '<a href="popableWindow.do?url=dashboardNotes.do&params=scoreCard:'+id+'" class="send"></a>'+
        ($("#scores").data(id).children > 0 ? '<a href="#'+id+'" class="expand"></a>' : '')+
        '<a href="popableWindow.do?url='+($("#scores").data(id).type == 'Indicador' ? 'dashboardPointer': ($("#scores").data(id).type == 'Proyecto' ? 'dashboardProject' : 'dashboardScoreCard'))+'.do&params=scoreCard:'+ id +'" class="dashboard"></a>'+
        '</p>'+
        '</div>'+
        '</li>');
    children = $("#scores").data(scoreParentNode.attr("scoreid")).children;
    if(scoreParentNode.children("ul").children("span.line").length < 2)
    {
        scoreParentNode.children("ul").prepend('<span class="horizontal line" parent="'+ scoreParentNode.attr("scoreid") +'" style="width:'+ (175*(children-1)+4) +'px; left:93px; top:15px;"></span>');
        scoreParentNode.children("ul").prepend('<span class="vertical line" parent="' + scoreParentNode.attr("scoreid") + '" style="height:15px; left:' + (95*children-2) +'px; top:0px;"></span>');
    }

    scoreParentNode.find(".annotate").colorbox({
        width:"692px",
        height:"400px",
        iframe:true
    });
    scoreParentNode.find(".dashboard").colorbox({
        width:"990px",
        height:"720px",
        iframe:true
    });
    scoreParentNode.find(".send").colorbox({
        width:"990px",
        height:"720px",
        iframe:true
    });
}

var currentAnchor = null;
function checkAnchor()
{
    if(currentAnchor != document.location.hash)
    {
        currentAnchor = document.location.hash;
        if(!currentAnchor || currentAnchor == "#")
        {
            resetScoreSection(null);
            $("#scores").delay(50).animate({
                marginLeft:0
            }, 200);
        }
        else if( currentAnchor == "#zero" )
        {
            resetScoreSection("zero");
            $("#scores").delay(50).animate({
                marginLeft:"-100%"
            }, 200);
        }
        else if( currentAnchor == "#une" )
        {
            resetScoreSection("une");
            $("#scores").delay(50).animate({
                marginLeft:"-200%"
            }, 200);
        }
        else if( currentAnchor == "#listview" )
            $(".listviewicon").click();
        else if( currentAnchor == "#graphview" )
            $(".graphviewicon").click();
    }
}
function resetScoreSection(section)
{
    $("#scores ul").css("display","none");
    if(section != null && section != "")
    {
        $("#scores ."+section).css("display","block");
        $("#scores ."+section).parentsUntil("#scores").css("display","block");
    }
}
//Build XML from String returned from controller
function buildXMLFromString(text) {
    if (window.DOMParser) {
        var parser = new DOMParser();
        try {
            xmlDoc = parser.parseFromString(text, "text/xml");
        } catch (e) {};
    }
    else {
        xmlDoc = CreateMSXMLDocumentObject ();
        if (!xmlDoc) {
            //alert ("Cannot create XMLDocument object");
            return false;
        }
        xmlDoc.loadXML (text);
    }

    var errorMsg = null;
    if (xmlDoc.parseError && xmlDoc.parseError.errorCode != 0) {
        errorMsg = "XML Parsing Error: " + xmlDoc.parseError.reason
        + " at line " + xmlDoc.parseError.line
        + " at position " + xmlDoc.parseError.linepos;
    } else {
        if (xmlDoc.documentElement) {
            if (xmlDoc.documentElement.nodeName == "parsererror")
                errorMsg = xmlDoc.documentElement.childNodes[0].nodeValue;
        }
        else
            errorMsg = "XML Parsing Error!";
    }

    if (errorMsg)
        return null;

    //alert ("Parsing was successful!");
    return xmlDoc;
}//Ends build XML